315B - Sereja and Array - CodeForces Solution


implementation *1200

Please click on ads to support us..

Python Code:

_, m = map(int, input().split(" "))
valores = list(map(int, input().split(" ")))
acumulador_de_incrementos = 0

for _ in range(m):
    operacao = list(map(int, input().split(" ")))
    
    if operacao[0] == 1:
        valores[operacao[1] - 1] = operacao[2] - acumulador_de_incrementos
    elif operacao[0] == 2:
        acumulador_de_incrementos += operacao[1]
    else:
        print(valores[operacao[1] - 1] + acumulador_de_incrementos)
        
        
        

C++ Code:

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <chrono>
#include <cstring>

#define INF 10000000000
#define MOD 1000000007

#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair

#define rep(i, n) for(int i = 0; i < n; ++i)
#define dbg(x) cerr << x << endl;

//author: @u_d_ash_

using namespace std;
using namespace std::chrono;


int main(){
    auto start = high_resolution_clock::now();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //code here
    ll n, m;
    cin >> n >> m;
    vector<ll> vec;
    vector<ll> ex(n, 0);
    ll count = 0;
    rep(i, n){
        ll x;
        cin >> x;
        vec.pb(x);
    }
    rep(i, m){
        ll a;
        cin >> a;
        if(a == 1){
            ll v, x;
            cin >> v >> x;
            ex[v - 1] = (x - (vec[v - 1] + count));
        }else if(a == 2){
            ll y;
            cin >> y;
            count += y;
        }else{
            ll q;
            cin >> q;
            cout << vec[q - 1] + ex[q - 1] + count << endl;
        }
    }



    auto stop = high_resolution_clock::now();
    auto dur = duration_cast<milliseconds>(stop - start);
    cerr << dur.count();
}


Comments

Submit
0 Comments
More Questions

1363A - Odd Selection
131B - Opposites Attract
490C - Hacking Cypher
158B - Taxi
41C - Email address
1373D - Maximum Sum on Even Positions
1574C - Slay the Dragon
621A - Wet Shark and Odd and Even
1395A - Boboniu Likes to Color Balls
1637C - Andrew and Stones
1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack
716A - Crazy Computer
644A - Parliament of Berland
1657C - Bracket Sequence Deletion
1657B - XY Sequence
1009A - Game Shopping
1657A - Integer Moves
230B - T-primes
630A - Again Twenty Five
1234D - Distinct Characters Queries
1183A - Nearest Interesting Number
1009E - Intercity Travelling
1637B - MEX and Array
224A - Parallelepiped
964A - Splits
1615A - Closing The Gap
4C - Registration System